package com.boatAnchorAssistant.service.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.boatAnchorAssistant.pojo.entity.ITable;
import com.boatAnchorAssistant.pojo.param.iTable.*;
import com.boatAnchorAssistant.pojo.vo.iTable.*;
import com.boatAnchorAssistant.pojo.dto.iTable.*;
import com.boatAnchorAssistant.service.repository.in.ITableRepository;
import com.boatAnchorAssistant.service.service.in.ITableService;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.utils.ids.IdGenerator;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;


import java.util.ArrayList;
import java.util.List;

/**
* 【描 述】：表单服务
* 【环 境】：J2SE 17
* 【详 细】：
*
*/
@Service
public class ITableServiceImpl implements ITableService {

private final ITableRepository iTableRepository;

public ITableServiceImpl(ITableRepository iTableRepository) {
this.iTableRepository = iTableRepository;
}


/**
* 创建表单
*
* @param param
*/
@Override
public void createITable(CreateITableParam param) {
ITable iTable =new ITable();
BeanUtils.copyProperties(param,iTable);
Long id = IdGenerator.SNOW.generate();
iTable.setId(id);
iTableRepository.create(iTable);
}

/**
* 修改表单
*
* @param param
*/
@Override
public void editITable(EditITableParam param) {
Long id = param.getId();
ITable iTable =iTableRepository.getByIdCheck(id);
BeanUtils.copyProperties(param,iTable);
iTableRepository.edit(iTable);
}

/**
* 移除表单
*
* @param id
*/
@Override
public void removeITable(Long id) {
iTableRepository.removeById(id);
}

/**
* 启动/禁用表单
*
* @param id
*/
@Override
public void enabledITable(Long id) {
ITable iTable =iTableRepository.getByIdCheck(id);
iTable.setIsDisable(!iTable.getIsDisable());
iTableRepository.edit(iTable);
}

/**
* 获取表单详情
*
* @param id
* @return
*/
@Override
public GetITableVo getITable(Long id) {
ITable iTable =iTableRepository.getByIdCheck(id);
GetITableVo vo=new GetITableVo();
BeanUtils.copyProperties(iTable,vo);
return vo;
}

/**
* 获取表单 列表
*
* @param param
* @return
*/
@Override
public PageResult< GetITableListVo> getITableList(GetITableListParam param) {

SelectITableDto dto = new SelectITableDto();
BeanUtils.copyProperties(param,dto);
Page< ITable > page = iTableRepository.selectITable(dto);
List< ITable > iTableList = page.getRecords();
List< GetITableListVo > list= new ArrayList<>();
for (ITable iTable : iTableList) {
GetITableListVo vo=new GetITableListVo();
BeanUtils.copyProperties(iTable,vo);

list.add(vo);
}
return new PageResult<>(list,page);

}

/**
* 获取表单下拉列表
*
* @param param
* @return
*/
@Override
public List< GetITableDownListVo > getITableDownList(GetITableDownListParam param) {
ITable po = new ITable();
if (param != null) {
BeanUtils.copyProperties(param, po);
}
List< ITable > iTableList = iTableRepository.getListByEntity(po);

List< GetITableDownListVo > list = new ArrayList<>();
for (ITable iTable : iTableList) {
GetITableDownListVo vo=new GetITableDownListVo();
BeanUtils.copyProperties(iTable,vo);
list.add(vo);
}
return list;
}


}



